/*
void *main_backend(void *param)
{
    nfc_device *device = NULL;
    MifareTag *tags = NULL;
    nfc_connstring devices[8];
    size_t device_count;

    nfc_context *context;
    nfc_init (&context);
    if (context == NULL)
		printf("Unable to init libnfc (malloc)");

    device_count = nfc_list_devices (context, devices, 8);
    if (device_count <= 0)
	{
		printf("No NFC device found.\n");
	}

	// look through all the readers
	printf("Device count: %d\n", device_count);
	size_t d;
    for (d = 0; d < device_count; d++)
    {
        device = nfc_open (context, devices[d]);

        if (!device)
        {
			printf("nfc_open() failed.\n");
            continue;
        }

		// look for all the tags connected to the current device
		tags = freefare_get_tags (device);

		if (tags == -1)
			printf("Error listing tags. -1\n");
		if (!tags)
		{
			printf("Error listing tags. 0\n");
			nfc_close (device);
		}

		// look through all the tags
		printf ("Looking at all the tags on reader #%d\n", d);
		int i;
		for (i = 0; tags[i]; i++)
		{
			printf ("Before  continue\n");
			enum mifare_tag_type tagnfc_openType;
			tagType = freefare_get_tag_type (tags[i]);
			printf("tagType = %d\n", tagType);
			if (DESFIRE != freefare_get_tag_type (tags[i]))
			continue;

			printf ("After  continue\n");

			char *tag_uid = freefare_get_tag_uid (tags[i]);
			char buffer[BUFSIZ];

			printf ("Found %s with UID %s. ", freefare_get_tag_friendly_name (tags[i]), tag_uid);

			int res;
			uint8_t ret_rx[CMD_SELECT_AID_SIZE_RX];
			int j;
			//BUFFER_INIT (ret, CMD_SELECT_AID_SIZE_RX);

			for (j = 0; j < sizeof(ret_rx); j++)
				ret_rx[j] = 0;

			res = mifare_desfire_connect (tags[i], &ret_rx[0]);

			//for (j = 0; j < sizeof(ret_rx); j++)
			//	printf("ret_rx[%d] = %x\n", j, ret_rx[j]);
			if (res < 0) {
				printf ("Can't connect to Mifare DESFire target.\n");
				break;
			}

			//for (j = 0;

			mifare_desfire_disconnect (tags[i]);

			free (tag_uid);
		}

		freefare_free_tags (tags);
		nfc_close (device);
    }
    nfc_exit (context);
}
*/